# -*- coding: utf-8  -*-
#!/usr/local/bin/python

__author__ = 'yaojian'

from misc.configbase import ConfigBase
from misc.cache import Cache
from cm.privilege.backend import ChannelManager

CHANNELS = [
    {
        "id" : 1,
        "channel" : "littleOrange",
        "key" : "c52c85e7e01a4e8a9206d9127d3b8cee",
        "domain" : [],
        "expiration" : "2015-12-31 23:59:59",
        "description": "小橙子服务平台",
    },
    {
        "id" : 2,
        "channel" : "littleOrangeMobile",
        "key" : "c08e8a0d460946859f37d23297233aa8",
        "domain" : [],
        "expiration" : "2015-12-31 23:59:59",
        "description": "littleOrangeMobile",
    }
]

class ChannelConf(ConfigBase):
    DICT = []

    @classmethod
    def all_data(cls):
        _cache_key = "System_Channel_Conf_DICT"
        _cache = Cache(backend="systemconfig")
        _conf_list = _cache.get(_cache_key) or []
        if not _conf_list:
            _manager = ChannelManager()
            _conf_list = _manager.query_config_dict()
            _cache.set(key = _cache_key, value = _conf_list)

            if not _conf_list:
                _conf_list = CHANNELS

            cls.DICT = _conf_list
            return _conf_list



